package tesys.business;

import java.util.List;

import tesys.application.Main;
import tesys.application.Services;
import tesys.objects.IterationTask;
import tesys.persistence.DataAccessStub;

public class AccessIterationTasks
{
	private DataAccessStub dataAccess;
	private List<IterationTask> elements;

	private IterationTask iterTask;
	private int currentIterationTask;

	private int currentIterationWithTask;


	public AccessIterationTasks()
	{
		dataAccess = (DataAccessStub) Services.getDataAccess(Main.dbName);
		elements = null;
		currentIterationTask = 0;
		currentCS = 0;
	}

	public IterationTask getIterationTasks(String iterationID)
	{
		if (elements == null)
		{
			elements = dataAccess.getIterationTasks(new IterationTask(iterationID, null));

			currentIterationTask = 0;
		}
		if (currentIterationTask < elements.size())
		{
			iterTask = (IterationTask) elements.get(currentIterationTask);
			currentIterationTask++;
		}
		else
		{
			elements = null;
			iterTask = null;
			currentIterationTask = 0;
		}
		return iterTask;
	}

	public IterationTask getTaskWithAllIterations(String taskID)
	{
		if (elements == null)
		{
			elements = dataAccess.getTaskWithAllIterations(new IterationTask(null,taskID));
		}
		if (currentIterationWithTask < elements.size())
		{
			iterTask = (IterationTask) elements.get(currentIterationWithTask);
			currentIterationWithTask++;
		}
		else
		{
			elements = null;
			iterTask = null;
			currentIterationWithTask = 0;
		}
		return iterTask;
	}

}
